import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';

class HttpLeaveService {
  static Future<Response> dashboardLeaves([int employeeId]) {
    return BaseConfig.httpBase.get('/api/dashboard/leaves', {
      'employee_id': employeeId,
    });
  }

  static Future<Response> leavesList([int employeeId, String type, int page]) {
    return BaseConfig.httpBase.get('/api/leaves', {
      'employee_id': employeeId,
      'type': type,
      'page': page,
    });
  }

  static Future<Response> leavesListByDateRange(
      [List<int> employeeIds,
      String type,
      int page,
      String startDate,
      String endDate]) {
    return BaseConfig.httpBase.get('/api/leaves', {
      'employee_ids': employeeIds.join(", "),
      'type': type,
      'page': page,
      'start_date': startDate,
      'end_date': endDate,
    });
  }

  static Future<Response> updateApplyLeave(
    int id,
    int employeeId,
    int leaveTypeId,
    String startDate,
    String startDateMeridian,
    String endDate,
    String endDateMeridian,
    String notes,
    List<int> attachmentIds,
  ) {
    return BaseConfig.httpBase.putJson('/api/leaves/$id', {
      "employee_id": employeeId,
      "leave_type_id": leaveTypeId,
      "start_date": startDate,
      "start_date_meridian": startDateMeridian,
      "end_date": endDate,
      "end_date_meridian": endDateMeridian,
      "notes": notes,
      "attachment_ids": attachmentIds,
    });
  }

  static Future<Response> applyLeave(
    int employeeId,
    int leaveTypeId,
    String startDate,
    String startDateMeridian,
    String endDate,
    String endDateMeridian,
    String notes,
    List<int> attachmentIds,
  ) {
    return BaseConfig.httpBase.postJson('/api/leaves', {
      "employee_id": employeeId,
      "leave_type_id": leaveTypeId,
      "start_date": startDate,
      "start_date_meridian": startDateMeridian,
      "end_date": endDate,
      "end_date_meridian": endDateMeridian,
      "notes": notes,
      "attachment_ids": attachmentIds,
    });
  }

  static Future<Response> leaveApprove(int id) {
    return BaseConfig.httpBase.postJson('/api/leaves/$id/approve', {});
  }

  static Future<Response> leaveReject(int id, String reason) {
    return BaseConfig.httpBase.postJson('/api/leaves/$id/reject', {
      'rejected_reason': reason,
    });
  }

  static Future<Response> batchLeaveAdjust(
      List<int> employeeIds, List leaveTypes) {
    return BaseConfig.httpBase.postJson('/api/leaves/adjust', {
      'employee_ids': employeeIds,
      'leave_types': leaveTypes,
    });
  }

  static Future<Response> batchLeaveApprove(List<int> leaveIds) {
    return BaseConfig.httpBase.postJson('/api/leaves/batch_approve', {
      'leave_ids': leaveIds,
    });
  }

  static Future<Response> batchLeaveReject(
      List<int> leaveIds, String rejectedReason) {
    return BaseConfig.httpBase.postJson('/api/leaves/batch_reject', {
      'leave_ids': leaveIds,
      'rejected_reason': rejectedReason,
    });
  }

  static Future<Response> batchLeaveDelete(List<int> leaveIds) {
    return BaseConfig.httpBase.postJson('/api/leaves/batch_delete', {
      'leave_ids': leaveIds,
    });
  }

  static Future<Response> batchLeaveWithdraw(List<int> leaveIds) {
    return BaseConfig.httpBase.postJson('/api/leaves/batch_withdraw', {
      'leave_ids': leaveIds,
    });
  }

  static Future<Response> withdrawLeave(int id) {
    return BaseConfig.httpBase.postJson('/api/leaves/$id/withdraw', {});
  }

  static Future<Response> showLeave(int id) {
    return BaseConfig.httpBase.get('/api/leaves/$id', {});
  }

  static Future<Response> calculateLeaveDays(int employeeId, String startDate,
      String startDateMeridian, String endDate, String endDateMeridian) {
    return BaseConfig.httpBase.postJson('/api/leaves/calculate_leave_days', {
      'employee_id': employeeId,
      'start_date': startDate,
      'start_date_meridian': startDateMeridian,
      'end_date': endDate,
      'end_date_meridian': endDateMeridian,
    });
  }
}
